import json

import requests

url = 'http://116.62.130.29/v1/workflows/run'

headers = {
    'Authorization': 'Bearer app-Fkr370nTyqFbXH3iAecejpZ7',
    'Content-Type': 'application/json'
}

payload = {
    "inputs": {"input": "hello"},
    "response_mode": "streaming",
    "user": "abc-123"
}
s = '''{'event': 'workflow_started', 'workflow_run_id': 'd034abe5-f7ad-4a83-b149-3f89a26c3eca', 'task_id': '75be9e5d-d783-4bec-a5cd-01689cb5d6fa', 'data': {'id': 'd034abe5-f7ad-4a83-b149-3f89a26c3eca', 'workflow_id': 'd0cd9d1f-3b7d-4734-83da-246796418ec6', 'inputs': {'input': 'hello', 'sys.files': [], 'sys.user_id': 'abc-123', 'sys.app_id': 'dbe63513-c6b1-437a-b6c9-d897c290287c', 'sys.workflow_id': 'd0cd9d1f-3b7d-4734-83da-246796418ec6', 'sys.workflow_run_id': 'd034abe5-f7ad-4a83-b149-3f89a26c3eca'}, 'created_at': 1755081333}}'''

##print(a)
response = requests.post(url, headers=headers, json=payload,stream=True)


for r in response.iter_lines():
    #print(type(r))
    s = r.decode('utf-8')
    #print(s)
    s = s.replace('data: ', '')
    #print(s)
    if s == '':
        continue
    d = json.loads(s)
    if d['event']=='text_chunk':
        print(d['data']['text'],end='')

